import { z } from "zod";
import path from "path";
import { fileURLToPath } from "url";
import { getDetailRecordProcessPrompt } from "../../prompts/index.js";
import { getMemoryDir } from "../../utils/paths.js";

// 详细记录过程工具
// Detail Record Process Tool
export const detailRecordProcessSchema = z.object({
  implementationResults: z
    .string()
    .min(50, {
      message: "实施结果不能少于50个字符，请提供更详细的实施过程和结果描述",
    })
    .describe("来自逐步尝试阶段的完整实施结果和过程记录"),
  recordingScope: z
    .array(z.enum(['decisions', 'implementations', 'tests', 'changes', 'lessons', 'metrics']))
    .optional()
    .default(['decisions', 'implementations', 'tests', 'changes'])
    .describe("记录范围选择列表"),
  evaluationFramework: z
    .array(z.enum(['quantitative', 'qualitative', 'comparative', 'long_term']))
    .optional()
    .default(['quantitative', 'qualitative'])
    .describe("评估框架选择列表"),
  knowledgeSharing: z
    .boolean()
    .optional()
    .default(true)
    .describe("是否进行知识分享和团队沉淀"),
  documentationLevel: z
    .enum(['basic', 'standard', 'comprehensive', 'enterprise'])
    .optional()
    .default('standard')
    .describe("文档化程度级别")
});

export async function detailRecordProcess({
  implementationResults,
  recordingScope = ['decisions', 'implementations', 'tests', 'changes'],
  evaluationFramework = ['quantitative', 'qualitative'],
  knowledgeSharing = true,
  documentationLevel = 'standard'
}: z.infer<typeof detailRecordProcessSchema>) {
  // 获取基础目录路径
  // Get base directory path
  const __filename = fileURLToPath(import.meta.url);
  const __dirname = path.dirname(__filename);
  const PROJECT_ROOT = path.resolve(__dirname, "../../..");
  const MEMORY_DIR = await getMemoryDir();

  // 使用prompt生成器获取最终prompt
  // Use prompt generator to get the final prompt
  const prompt = await getDetailRecordProcessPrompt({
    implementationResults,
    recordingScope,
    evaluationFramework,
    knowledgeSharing,
    documentationLevel,
    memoryDir: MEMORY_DIR,
  });

  return {
    content: [
      {
        type: "text" as const,
        text: prompt,
      },
    ],
  };
}